package com.mindainfo.groundwave.server.base.component;

import com.alibaba.fastjson.JSON;
import com.mindainfo.groundwave.server.member.bean.SysDept;
import com.mindainfo.groundwave.server.member.mapper.SysDeptMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by MD-01 on 2017/5/3.
 */
@Component
public class Starting implements InitializingBean{

    private Logger logger = LoggerFactory.getLogger("starting");
    @Resource
    private BaseInfo info;
    @Resource
    private SysDeptMapper deptMapper;

    @Override
    public void afterPropertiesSet() throws Exception {
        /**
         * 这里可以指定一些项目启动后初始化的操作.
         * 运行到这里项目已经启动.spring的bean加载完成
         * 这里可以注入其他的bean
         */
        System.out.println("abc");
        System.out.println(deptMapper);

        SysDept sysDept = deptMapper.queryBaseDept();
        if(sysDept!=null){
            sysDept.setName(info.getOrganization());
            sysDept.setManagerName(info.getManagerName());
            sysDept.setManagerPhone(info.getManagerPhone());
            deptMapper.updateById(sysDept);
        }
        //没有顶级组织,新建
        else{
            SysDept dept = new SysDept();
            dept.setParentId(0);
            dept.setName(info.getOrganization());
            dept.setManagerName(info.getManagerName());
            dept.setManagerPhone(info.getManagerPhone());
            deptMapper.insert(dept);
        }
        logger.info("项目启动成功...");

    }
}
